<template>
  <div class="home">
    <template v-for="item in homeList">
      <van-card
        :key="item.id"
        :price="item.price"
        desc="描述信息"
        :title="item.goodsName"
        :thumb="item.img"
      >
        <!-- 具名插槽 -->
        <template #footer>
          <van-button type="primary" @click="handleToCart(item)" size="mini">
            加入购物车
          </van-button>
        </template>
      </van-card>
    </template>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from 'vuex'
export default {
  name: 'HomeView',
  components: {},
  computed: {
    ...mapState(['homeList']),
  },
  created() {
    this.fetchCartList()
  },
  methods: {
    ...mapActions(['fetchCartList']),
    ...mapMutations(['to_cart']),
    handleToCart(item) {
      console.log(item, 'item')
      this.to_cart(item)
    },
  },
}
</script>
